/**
 * ProductDao.java
 * @author xsm
 * date 2012-8-8
 */

package com.netistate.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.netistate.base.BaseDao;
import com.netistate.pojo.Demo;
import com.netistate.pojo.Product;

@Repository
public class ProductDao extends BaseDao<Product, Integer>{
	
	/**
	 * 查询全部
	 * @param product
	 * @return
	 */
	public Product findAll(Product product){
		String hql = "from Product where id=?";
		Query query = getSession().createQuery(hql);		
		return (Product) query.list();
	}

	/**
	 * 根据ProductNo去找product
	 * @param productNo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Product> findProductByProductNo(String productNo) {
		String hql = "from Product where product = ?";
		Query query = getSession().createQuery(hql);
		query.setParameter(0, productNo);
		return query.list();
	}

	/**
	 * 根据projectId找product
	 * @param pid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Product> findProductByProjectId(int pid) {
		String hql = "from Product where projectid = ?";
		Query query = getSession().createQuery(hql);
		query.setInteger(0, pid);
		return query.list();
	}

}
